// pages/find/apply-detail/apply-detail.js
import {HTTP} from '../../../utils/http.js'
let ajax = new HTTP()
var app = getApp()

Page({
    data: {
        imgUrls: [],
        pic: [],
        applyId: "",
        applyTitle: "",
        isApply: 0,
        applyTime: "",
        applyAddress: "",
        applyUnits: ""
    },
    onLoad(options) {
        this.data.applyId = options.id
        this.data.applyTitle = options.title
        wx.setNavigationBarTitle({
            title: this.data.applyTitle
        })
        this._getApplyInfo(app.globalData.memberid, this.data.applyId)
    },
    // 转发 
    onShareAppMessage: function () {

    },
    // 请求数据
    _getApplyInfo(memberid, applyid) {
        ajax.request({
            url: "sportslist/read",
            data: {
                id: applyid,
                memberid: memberid
            },
            success: (res) => {
                if (res.rescode === "0000") {
                    res = res.data
                    let ImgArr = []
                    ImgArr.push({
                        bannerpic: res.pic,
                        name: res.title
                    })
                    if (res.sportway != null) {
                        this.setData({
                            sportway: res.sportway,
                        })
                    }
                    if (res.awartsetting != null) {
                        this.setData({
                            awartsetting: res.awartsetting
                        })
                    }
                    this.setData({
                        imgUrls: ImgArr,
                        isApply: res.hassub,
                        applyTime: res.sporttime,
                        applyAddress: res.sportarea,
                        applyUnits: res.sportcomp,
                        // sportway: res.sportway,
                        // awartsetting: res.awartsetting
                    })
                    wx.setStorageSync('pic', res.pic)
                    wx.setStorageSync('title', res.title)
                    wx.setStorageSync('prize', res.sportfee)
                    wx.setStorageSync('isPay', res.isfree)
                }
            }
        })
    },
    // 参加报名
    joinApply() {
        wx.navigateTo({
            url: 'detail/detail?id=' + this.data.applyId + '&title=' + this.data.applyTitle
        })
    },
})